package org.blogsite.greencode.bean.test;

import java.util.Date;
import java.util.Iterator;

import org.blogsite.greencode.bean.InstructorManage_Instructor;
import org.blogsite.greencode.bean.Schooling_Instructor_Course;
import org.blogsite.greencode.bean.SystemBulletinBoard;
import org.blogsite.greencode.bean.TeachingSupport_Course;
import org.blogsite.greencode.bean.TeachingSupport_Resource;
import org.blogsite.greencode.bean.User;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.jasypt.util.password.BasicPasswordEncryptor;
/**
 * @author:wzj E-mail: jsun789@gmail.com
 * @date:2010-7-23 下午06:42:51
 */
public class Create_table_easy {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		TeachingSupport_Course course=new TeachingSupport_Course();
		course.setCredit(99);
		course.setDescribe("hehea");
		course.setName("java");
		course.setPeriod(999);
		course.setType("1");
		/*测试课程*/
		TeachingSupport_Course course1=new TeachingSupport_Course();
		course1.setCredit(99);
		course1.setDescribe("hehex");
		course1.setName("struts");
		course1.setPeriod(1000);
		course1.setType("2");
		//设置讲师信息
		InstructorManage_Instructor im=new InstructorManage_Instructor();
		im.setJob_num("082188111");
		im.setEmail("xixiaa");
		im.setName("jsun");
		im.setSex("female");
		
		/*设置管理员,因为用了jasypt开源项目,密码需要先加密存储,在这边添加管理员帐号*/
		BasicPasswordEncryptor bpe=new BasicPasswordEncryptor();
		//习惯先用名字
		String userName="admin";
		String adminPassword="greencode";
		String adminJobNum="082188001";
		
		User user=new User();
		user.setUsername(userName);
		//设置加密
		user.setPassword(bpe.encryptPassword(adminPassword));
		user.setType("manager");
		user.setJob_num(adminJobNum);
		/*添加公告*/
		SystemBulletinBoard sysBoard=new SystemBulletinBoard();
		SystemBulletinBoard sysBoard2=new SystemBulletinBoard();
		sysBoard.setTitle("good news");
		sysBoard.setBody("Very high level of configuration capabilities: The developer can implement tricks like instructing an encryptor to ask a, for example, remote HTTPS server for the password to be used for encryption. It lets you meet your security needs.");
		sysBoard.setUsername("admin");
		sysBoard2.setTitle("open the door");
		sysBoard2.setBody("Jasypt is a java library which allows the developer to add basic encryption capabilities to his/her projects with minimum effort, and without the need of having deep knowledge on how cryptography works.");
		sysBoard2.setUsername("admin");

		try {
			Session session = HibernateSessionFactory.getSession();
			Transaction tx = session.getTransaction();
			tx.begin();
			session.save(course);
			session.save(course1);
			session.save(im);
			session.save(sysBoard);
			session.save(sysBoard2);
			session.save(user);
			
			System.out.println("success");
			tx.commit();
			HibernateSessionFactory.closeSession();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
